import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { ComponentPropsType } from "../../components/QuestionComponents";

// 单个组件类型
export type ComponentInfoType = {
  fe_id: string;
  type: string;
  title: string;
  props: ComponentPropsType; // 引入定义的属性类型
};
// 当前模块存储的列表
export type ComponentsStateType = {
  componentList: ComponentInfoType[];
};

const INIT_STATE: ComponentsStateType = {
  componentList: [],
};

export const componentsSlice = createSlice({
  name: "components",
  initialState: INIT_STATE,
  reducers: {
    // 重置所有组件
    resetComponents: (
      state: ComponentsStateType,
      action: PayloadAction<ComponentsStateType>
    ) => {
      return action.payload;
    },
  },
});
export const { resetComponents } = componentsSlice.actions;
export default componentsSlice.reducer;
